package com.film.admincontroller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Director;
import com.film.service.DirectorService;
import com.film.service.impl.DirectorServiceImpl;


@WebServlet("/director.do")
public class DirectorServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		DirectorService service = new DirectorServiceImpl();
		List<Director> directorCount = service.selectDirector();
		List num=service.pageNum();
		int firstPage = 1;
		int p=0;
		int selectPageNum=7;
		if(req.getParameter("firstPage")!=null) {
			firstPage=Integer.parseInt(req.getParameter("firstPage")) ;
			p = (firstPage-1)*selectPageNum;
		}
		List director=	service.selectDirector(p, selectPageNum);
		/* service.selectDirector(, 7); */
//		req.setAttribute("director", director);
//		req.getRequestDispatcher("admin/director.jsp").forward(req, resp);
		HttpSession session = req.getSession();
		session.setAttribute("directorCount",directorCount);
		session.setAttribute("director",director);
		session.setAttribute("firstPage", firstPage);
		session.setAttribute("pagenum",num);
		resp.sendRedirect("admin_jsp/director.jsp");
	}
}
